#include "currweatherbox.h"

CurrWeatherBox::CurrWeatherBox(QWidget *parent,bool isNew)
    : QWidget{parent}
{
    color = QColor (255, 255, 255);
    layout=new QVBoxLayout(this);
    text=new QLabel();
    if(isNew){
        text_1=new QLabel();
        text_2=new QLabel();
        text_3=new QLabel();
    }
    text->setScaledContents(true);
    layout->addWidget(text);
    this->setStyleSheet(R"(
        QLabel {
            font-size: 20px;
            font-weight: bold;
        }
    )");
}

void CurrWeatherBox::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    
    // 创建 QPainter 对象
    QPainter painter(this);
    
    // 启用抗锯齿效果，使绘制更加平滑
    painter.setRenderHint(QPainter::Antialiasing);
    
    // 设置画笔颜色和宽度
    QPen pen;
    pen.setColor(this->color);  // 设置边框颜色为黑色
    pen.setWidth(0);  // 设置边框宽度
    painter.setPen(pen);
    
    // 设置画刷颜色
    QBrush brush;
    brush.setColor(this->color);  // 设置填充颜色为浅蓝色
    brush.setStyle(Qt::SolidPattern);
    painter.setBrush(brush);
    
    // 获取控件的矩形区域
    QRect rect = this->rect();
    
    // 绘制圆角矩形，rect 是控件的区域，设置圆角半径为 15
    painter.drawRoundedRect(rect, 15, 15);
}
void CurrWeatherBox::set_text(QString text){
    this->text->setStyleSheet(R"(
        QLabel {
            font-size: 16px;
        }
    )");
    this->text->setText(text);
}
void CurrWeatherBox::set_text(QString text,QString text1,QString text2,QString text3)
{
    if(text_1==nullptr||text_2==nullptr||text_3==nullptr){
        return;
    }
    layout->addWidget(text_1);
    layout->addWidget(text_2);
    layout->addWidget(text_3);

    this->text->setText(text);
    text_1->setText(text1);
    text_2->setText(text2);
    text_3->setText(text3);
    this->text->setScaledContents(true);
    text_1->setScaledContents(true);
    text_2->setScaledContents(true);
    text_3->setScaledContents(true);
    text_1->setStyleSheet(R"(
        QLabel {
            color:rgb(255, 50, 50);
        }
    )");
    text_2->setStyleSheet(R"(
        QLabel {
            color:rgb(30, 153, 92);
        }
    )");
    //204, 235, 255
    text_3->setStyleSheet(R"(
        QLabel {
            color:rgb(84, 194, 240);
        }
    )");
}

void CurrWeatherBox::set_text(QPixmap pixmap)
{
    this->text->setPixmap(pixmap);
    text->setMaximumSize(120,160);
}
